package org.acme.latch;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sql.DataSource;

public class MySqlLatchUtils {

    static Logger logger = LoggerFactory.getLogger(MySqlLatchUtils.class);

    public static void inLatch(DataSource dataSource, MysqlLatchListener mysqlLatchListener) {
        MySqlLatch mySqlLatch = null;
        try {
            mySqlLatch = new MySqlLatch(dataSource, mysqlLatchListener);
            mySqlLatch.start();
        } catch (Exception e) {
            logger.warn("MySqlLatchUtils error :" + e.getMessage());
        } finally {
            if (mySqlLatch != null) {
                mySqlLatch.stop();
            }
        }
    }
}
